#include "../inc/Receiver.hxx"
#include "../inc/Utils.hxx"

#define length(a) (sizeof(a)/sizeof(*a))

using namespace std;
using namespace boost;

int Receiver::SAMPLING_FREQUENCY = 2*Utils::CARRIER_FREQUENCY;
int Receiver::ECHO_BUFFER_SIZE = 700;

Receiver::Receiver() {
	echoBuffer = circular_buffer<vector<Echo> >(ECHO_BUFFER_SIZE);
}

void Receiver::pong(Echo echo) {  	//TODO nie do końca jestem pewny tej funkcji (jak jest z przesunieciem fazy gdy beda 2 obiekty w wiazce???)
	vector<Echo> receivedEcho(32+1);  	//32 wiersze anteny + SLB
	receivedEcho[0] = echo;
	complex<double> phaseShift(0, Antenna::ROW_DISTANCE*sin(echo.getElevationAngle()));
	for(int row = 1; row < receivedEcho.size(); row++) {
		receivedEcho[row] = echo;
		phaseShift *= row;
		vector<complex<double> >::iterator echoIterator;
		for(echoIterator = receivedEcho[row].begin(); echoIterator != receivedEcho[row].end(); ++echoIterator) {
			(*echoIterator) += phaseShift;
		}
	}
	echoBuffer.push_back(receivedEcho);
}
